Page({
  data:{
    name:'',
    phone:'',
    email:'',
    company:'',
    duties:'',
    desc:'',
    msg:'',
    hiddenModal:true
  },
  inputname:function(e){
   this.setData({
      name:e.detail.value,
   });
  },
  inputemail:function(e){    
    this.setData({
       email:e.detail.value,
    })
  },
  inputphone:function(e){  
    this.setData({     
      phone:e.detail.value,
   });   
  },
  inputcompany:function(e){
      this.setData({
      company:e.detail.value,
   });
  },
  inputduties:function(e){
     this.setData({
      duties:e.detail.value,
     });
  },
  inputdesc:function(e){
     this.setData({
       desc:e.detail.value,
     });
  },
  createImage:function(options){
       var info="BEGIN:VCARD\n"+"FN:"+this.data.name+"\n"+"TITLE:"+this.data.duties+"\n"+"ORG:"+this.data.company+"\n"+"TEL:WORK"+this.data.phone+"\n"+"EMIAL:WORK"+this.data.email+"\n"+"NOTE:"+this.data.desc+"\n"+"END:VCARD";
       var that=this;
       var name=that.data.name;
       if(this.data.name==null || this.data.name.length==0){
          that.setData({
           msg:'请重新填写姓名！',
             hiddenModal:!that.data.hiddenModal,
         });         
        return false;
       }
       var r=/\d+/
       if(r.test(this.data.phone)==false){
        
           that.setData({
           msg:'请重新输入手机号！',
             hiddenModal:!that.data.hiddenModal,
         });         
        return false;
       }
      wx.request({
      url: 'https://lendgiant.cn/index/createImage',
      data: {'info':info,'name':name},
      header: {'Content-Type': 'application/json'},
      method: 'GET',
        success: function(res){
      console.log("https://lendgiant.cn"+res.data.imgurl); 
  wx.navigateTo({url:'/pages/QRimg/QRimg?imgurl='+res.data.imgurl+"&name="+name}); 
        }
       });     
  },
    listenerConfirm:function(){
      this.setData({
           hiddenModal:!this.data.hiddenModal
         })
  },
  listenerCancel:function(){
      this.setData({
           hiddenModal:!this.data.hiddenModal
         })
  },

  onLoad:function(options){
    // 页面初始化 options为页面跳转所带来的参数
  },
  onReady:function(){
    // 页面渲染完成
  },
  onShow:function(){
    // 页面显示
  },
  onHide:function(){
    // 页面隐藏
  },
  onUnload:function(){
    // 页面关闭
  },
   onShareAppMessage: function () {
    return {
      title: '再小的个体也有自己名片',
      desc: '发布自己的电子名片',
      path: '/pages/tongxunlu/tongxunlu'
    }
  }
})